import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    //path: '/',
    path: '/pnl_analysis',
    component: Layout,
    //redirect: '/pnl_analysis',
    redirect: '/pnl_analysis/single_product',
    name: 'pnl_analysis',
    meta: {
      title: '测试目录',
      icon: 'nested'
    },
    children: [
      {
        path: 'single_product',
        component: () => import('@/views/pnl_analysis/single_product/index'), // Parent router-view
        name: 'single_product',
        meta: { title: 'single_product' },
      },
      {
        path: 'cross_products',
        component: () => import('@/views/demo/cross_product/index'),
        name: 'cross_products',
        meta: { title: 'cross_products' }
      },
      {
        path: 'total_products',
        component: () => import('@/views/nested/menu1/menu1-1'),
        name: 'total_products',
        meta: { title: 'total_products' }
      },
      {
        path: 'demo',
        component: () => import('@/views/demo/single_product/index'),
        name: 'demo',
        meta: { title: 'demo' }
      },
      {
        path: 'tables',
        component: () => import('@/views/demo/tables/index'),
        name: 'tables',
        meta: { title: 'tables' }
      },
      {
        path: 'table2',
        component: () => import('@/views/demo/tables/table2'),
        name: 'table2',
        meta: { title: 'table2' }
      },
      {
        path: 'jump',
        component: () => import('@/views/demo/single_product/jump'),
        name: 'jump',
        meta: { title: 'jump' }
      },
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'dashboard',
        meta: { title: 'dashboard' }
      },
    ]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/pnl_analysis',
    //redirect: '/dashboard',
    // children: [{
    //   path: 'dashboard',
    //   name: 'Dashboard',
    //   component: () => import('@/views/dashboard/index'),
    //   meta: { title: 'Dashboard', icon: 'dashboard' }
    // }]
  },

  {
    path: '/monitor',
    component: Layout,
    redirect: '/monitor/stock/summer',
    name: 'monitor',
    meta: {
      title: '产品运行监控',
      icon: 'nested'
    },
    children: [
      {
        path: 'stock',
        component: () => import('@/views/pnl_analysis/tables/index'),
        name: 'stock',
        meta: { title: '股票资产产品' },
        children: [
          {
            path: 'summer',
            component: () => import('@/views/pnl_analysis/tables/summer'),
            name: 'summer',
            meta: { title: '概述' }
          },
          {
            path: 'single',
            component: () => import('@/views/pnl_analysis/tables/single'),
            name: 'single',
            meta: { title: '单产品' }
          }
        ]
      }
    ]
  },
  {
    path: '/analysis',
    component: Layout,
    redirect: '/analysis/trade_result/single_account',
    name: 'analysis',
    meta: {
      title: '交易结果分析',
      icon: 'nested'
    },
    children: [
      {
        path: 'trade_result',
        component: () => import('@/views/pnl_analysis/tables/index'),
        name: 'trade_result',
        meta: { title: '股票资管' },
        children: [
          {
            path: 'single_account',
            component: () => import('@/views/pnl_analysis/single_product/index'),
            name: 'single_account',
            meta: { title: '单账户分析' }
          },
          {
            path: 'single_account2',
            component: () => import('@/views/pnl_analysis/tables/single'),
            name: 'single_account2',
            meta: { title: '只有一个菜单缩减' }
          }
        ]
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
